﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GPTB2
{
    public partial class frmGPTB2 : Form
    {
        public frmGPTB2()
        {
            InitializeComponent();
        }

        private void btnGiai_Click(object sender, EventArgs e)
        {
            // lay gia tri tu textbox
            int A, B, C;
            A = int.Parse(txtA.Text);
            B = int.Parse(txtB.Text);
            C = int.Parse(txtC.Text);

            // xu ly cac gia tri lay dc
            double delta = 0;

            // tinh delta
            delta = B * B - 4 * A * C;

            string Loigiai = "";
            if (delta == 0)
            {
                // neu delta = 0
                // x1 = x2 = -b/2a
                float x1 = 0;
                x1 = -B / (2 * A);
                Loigiai = "Phuong trinh co 1 nghiem kep x1 = x2 = " + x1;
            }
            else if (delta > 0)
            {
                // 2 nghiem phan biet
                double x1, x2 = 0;
                x1 = (-B + Math.Sqrt(delta)) / (2 * A);
                x2 = (-B - Math.Sqrt(delta)) / (2 * A);
                Loigiai = "Phuong trinh co 2 nghiem phan biet : x1 = " + x1 + " , x2 = " + x2; 
            }
            else
            {
                Loigiai = "Phuong trinh vo nghiem";
            }

            lblKetQua.Text = Loigiai;
        }
    }
}
